package com.zkingsoft.plugin.util;

import java.io.File;

import javax.servlet.http.HttpServletRequest;

import com.zkingsoft.config.SystemConstance;

/**
 * 获取项目路径格式
 * @author Ron
 * @createTime 2014.08.30
 */
public class WebUtils {

    /**
     * <li>功能简述:获取项目的实际路径
     * <li>详细描述:WEB-INF
     */
    public static String getContextPath() {

        String name = WebUtils.class.getName();
        name = SystemConstance.LEFT_SLASH + name.replaceAll(SystemConstance.CHARACTER_ALL, SystemConstance.CHARACTER_LEFT) + SystemConstance.CLASS_FILE_EXTEND_NAME;
        String space = SystemConstance.SPACE_REPLEACE_STRING;
        String path = WebUtils.class.getResource(name).getPath();
        path = path.substring(0, path.indexOf(SystemConstance.CONFIG_ROOT) + SystemConstance.CONFIG_ROOT.length());
        path = path.replaceAll(space, SystemConstance.CHARACTER_BLANK);
        if (path.startsWith(SystemConstance.FILE_PROTOCOL)) {
            path = path.substring(SystemConstance.FILE_PROTOCOL.length());
        }
        return path;
    }

    /**
     * <li>功能简述:获得发布目录路径
     * <li>详细描述:webapps
     */
    public static String getDeployPath() {

        File tempDir = new File(getContextPath());
        return tempDir.getParentFile().getParentFile().getAbsolutePath();
    }

    /**
     * <li>功能简述:获得项目目录
     */
    public static String getWebPath() {

        File tempDir = new File(getContextPath());
        return tempDir.getParentFile().getAbsolutePath();
    }
    /**
     * 
     * 
     * @description  获取客户端ip地址
     * @data 2015年8月6日 下午7:15:38 
     * @author Administrator
     * @param request
     * @return
     */
    public static String getCustomerIp(HttpServletRequest request) {
		String ip = request.getRemoteAddr();
		return ip;
	}
}
